<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Java实训课程 - 统计</title>
<!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
<script src="libs/jquery-1.12.1.min.js"></script>
<link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link href="libs/nv.d3.min.css" rel="stylesheet">
<script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
<script src="libs/d3.v3.min.js"></script>
<script src="libs/handlebars.min.js"></script>
<script src="libs/nv.d3.min.js"></script>
<script src="libs/js.cookie-2.1.0.min.js"></script>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="page-header">
				<h2>
					<strong>周浩账本</strong>
					<button id="querynull" class="btn btn-primary pull-right">退出</button>
				</h2>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="col-md-8">
			<ul class="nav nav-pills">
				<li><a href="index.html">首页</a></li>
				<li><a href="shouru.html">新加收入</a></li>
				<li><a href="zhichu.html">新加支出</a></li>
				<li><a href="query.html">查询</a></li>
				<li class="active"><a href="count.html">统计</a></li>
				<li><a href="#">用户：<span id="nickname"></span></a></li>
			</ul>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<hr />
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-6">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>当月收入总和</p>
					</div>
					<div class="panel-body">
						<h1 id="text1" align="center"></h1>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>当月支出总和</p>
					</div>
					<div class="panel-body">
						<h1 id="text2" align="center"></h1>
					</div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>类别收入</p>
					</div>
					<div class="panel-body" id="list1" align="center"></div>
				</div>
			</div>
			<div class="col-md-6">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>类别支出</p>
					</div>
					<div class="panel-body" id="list2" align="center"></div>
				</div>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-6" id="chart">
				<p class="text-center">
					<br />
				<hr />
				<strong>使用统计</strong>
				<svg style="height: 480px; width: 100%"></svg>
				<br />
				</p>
			</div>
			<div class="col-md-6" id="chart1">
				<p class="text-center">
					<br />
				<hr />
				<svg style="height: 480px; width: 100%"></svg>
				<br />
				</p>
			</div>
		</div>
	</div>
	<script type="text/x-handlebars-template" id="template">
    {{#each item}}
    <div class="panel panel-default col-md-3">
      <div class="panel-body">
        <dl>
          <dt>总和</dt> <dd>{{sumin}}</dd>
          <dt>平均</dt> <dd>{{avgin}}</dd>
          <dt>类别</dt> <dd>{{kind}}</dd>
       </dl>
     </div>
   </div>
   {{/each}}
   {{#each item1}}
    <div class="panel panel-default col-md-3">
      <div class="panel-body">
        <dl>
          <dt>总和</dt> <dd>{{sumout}}</dd>
          <dt>平均</dt> <dd>{{avgout}}</dd>
          <dt>类别</dt> <dd>{{kind}}</dd>
       </dl>
     </div>
   </div>
   {{/each}}
 </script>
	<script type="text/javascript">
		if (!Cookies.get("user")) {
			window.location.href = 'login.html';
		}
		$(function() {
			$.getJSON('queryMthin.action', function(res) {
				//console.log(res);
				$('#text1').text(res.moin)
			})

			$.getJSON('queryMthout.action', function(res) {
				$('#text2').text(res.moout)
			})

			$.getJSON('queryUsers.action', function(res) {
				//console.log(res);  
				$('#nickname').text(res.nk)
			})

			$.getJSON('querylin.action', function(res) {
				//console.log(res); 
				var data = {
					'item' : res
				};
				var t = Handlebars.compile($('#template').html());
				$('#list1').html(t(data));
			})

			$.getJSON('querylout.action', function(res) {
				console.log(res);
				var data = {
					'item1' : res
				};
				var t = Handlebars.compile($('#template').html());
				$('#list2').html(t(data));
			})

			$.getJSON('querylin.action', function(res) {
				nv.addGraph(function() {
					var chart = nv.models.pieChart().x(function(d) {
						return d.kind
					}).y(function(d) {
						return d.sumin
					}).showLabels(true).labelType('percent');
					d3.select("#chart svg").datum(res).transition().duration(
							350).call(chart);
					return chart;
				})
			})

			$.getJSON('querylout.action', function(res) {
				nv.addGraph(function() {
					var chart = nv.models.pieChart().x(function(d) {
						return d.kind
					}).y(function(d) {
						return d.sumout
					}).showLabels(true).labelType('percent');
					d3.select("#chart1 svg").datum(res).transition().duration(
							350).call(chart);
					return chart;
				})
			})

			$('#querynull').click(function() {
				$.post('querynull.action', {}, function(res, status) {
					if ('OK' == res) {
						alert('确定退出本次登陆');
					}
					window.location.href = "login.html";
				});
			});

		})
	</script>
</body>
</html>